package com.imooc.ecommerce.stream.qinyi;

import com.alibaba.fastjson.JSON;
import com.imooc.ecommerce.vo.QinyiMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.integration.support.MessageBuilder;

/**
 * 使用自定义的通信信道 QinyiSource 实现消息的发送
 * @author zhangshao
 * @since 2023/12/10 23:08
 */
@Slf4j
@EnableBinding(QinyiSource.class)
public class QinyiSendService {

    @Autowired
    private QinyiSource qinyiSource;

    /**
     * 使用自定义输出信道发送消息
     * @param message
     */
    public void sendMessage(QinyiMessage message){
        String _message = JSON.toJSONString(message);
        log.info("in QinyiSendService send message:[{}]",_message);
        qinyiSource.qinyiOutput().send(
                MessageBuilder.withPayload(_message).build()
        );
    }
}
